$(function(){
    var id = location.search.slice(1).split("=")[1].split("&")[0]
   
    var ide = location.search.slice(1).split("=")[2]
    console.log(ide);
    // 商品详情
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getproduct",
        data: {
            productid:id
        },
        dataType: "json",
        success: function (res) {
            console.log(res);
            var html = template("prtp",res)
            $(".nav-bar").before(html)
               // 价钱
               $(".nav-bar").after(template("tabtp",res))
               $(".re").after(template("mbxtp2",res))
        }
    });
 


    //  评论
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getproductcom",
        data: {
            productid:id
        },
        dataType: "json",
        success: function (res) {
            console.log(res);
            $(".comment-contents").html(template("pltp",res))
            
        }
    });



    var headerbox = document.querySelector('.mmb_header')
    // 获取小点点
    var topbox = document.querySelector(".to-top")
    // 获取头部盒子的高度
    var headerH = headerbox.offsetHeight
    console.log(headerH);
    window.onscroll=function(){
        var movertop = document.body.scrollTop + document.documentElement.scrollTop;
        if(movertop >headerH){
            topbox.style.display="block"
        }else{
            topbox.style.display="none"

        }
        topbox.onclick=function(){
            console.log(movertop);
            document.documentElement.scrollTop = 0+"px"
            
        }
        
    }


    // 面包屑
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getcategorybyid",
        data: {
            categoryid:ide
        },
        dataType: "json",
        success: function (res) {
            console.log(res);
            $(".sy").after(template('mbxtp',res))
        }
    });
})